package hu.blok1.veilingsite.server;

import hu.blok1.veilingsite.shared.Product;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GetProductObject {

	public static Product GetSingleProduct(ResultSet result) {
		Product product = new Product();
		try {
			while (result.next()) {
				product.setProductID(result.getInt("id"));
				product.setName(result.getString("name"));
				product.setDescription(result.getString("description"));
				// product.setImage(result.getString("image"));
				product.setMinimumPrize(result.getInt("minimumprice"));
				product.setStartDate(result.getDate("startdate"));
				product.setEndDate(result.getDate("enddate"));
				product.setStatus(result.getString("status"));
				product.setUserID(result.getInt("fk_user_id"));
				product.setCategory(result.getString("category"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return product;
	}

	public static List<Product> GetMultiProduct(ResultSet result) {
		List<Product> productList = new ArrayList<Product>();

		try {
			while (result.next()) {
				Product product = new Product();
				product.setProductID(result.getInt("id"));
				product.setName(result.getString("name"));
				product.setDescription(result.getString("description"));
				// product.setImage(result.getString("image"));
				product.setMinimumPrize(result.getInt("minimumprice"));
				product.setStartDate(result.getDate("startdate"));
				product.setEndDate(result.getDate("enddate"));
				product.setStatus(result.getString("status"));
				product.setUserID(result.getInt("fk_user_id"));
				product.setCategory(result.getString("category"));
				productList.add(product);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return productList;
	}
}